#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys


def myprint(obj, end='\n'):
    sys.stdout.write(str(obj) + end)


def main():
    with open('test.py', 'r') as f:
        for line in f:
            r = map(line.find, ('sys', 'line', 'print'))
            #数据量大时这里做了很多无用功，效率不高，可能可以建个函数只要依次判断到符合的元素就返回
            if [x for x in r if x > 0] != []:
                myprint(line.rstrip())

    # re
    import re
    with open('test.py', 'r') as f:
        for line in f:
            if re.search(r'sys|line|print', line):
                myprint(line.rstrip())


if __name__ == '__main__':
    main()
    myprint('done')
